Skip to content

Recover Codex CLI usage from prolite decode errors#719

Closed
beginnerslvl wants to merge 2 commits intosteipete:mainfrom
beginnerslvl:prolite-rate-limit-recovery
Closed

Recover Codex CLI usage from prolite decode errors#719
beginnerslvl wants to merge 2 commits intosteipete:mainfrom
beginnerslvl:prolite-rate-limit-recovery

Conversation

@beginnerslvl
Copy link
Copy Markdown

Summary

  • recover Codex CLI usage and credits from the JSON body embedded in account/rateLimits/read decode errors
  • keep the existing TTY /status fallback, but avoid depending on it when the RPC error already contains usable Pro Lite usage data
  • add regression coverage for prolite decode mismatch payload recovery

Validation

  • swift run CodexUsageRecoveryHarness (temporary local verification harness, removed before commit)
  • ./.build/lint-tools/bin/swiftformat Sources Tests --lint
  • env DYLD_FRAMEWORK_PATH=/Library/Developer/CommandLineTools/usr/lib ./.build/lint-tools/bin/swiftlint --strict

Notes

  • swift test --filter CodexUsageFetcherFallbackTests is blocked in this local CLT-only environment because XCTest is unavailable
  • pnpm check is blocked on this machine because Scripts/lint.sh invokes swiftlint without the required DYLD_FRAMEWORK_PATH

Closes #717

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 67a6bc2c4e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread Sources/CodexBarCore/UsageFetcher.swift Outdated
Comment on lines +571 to +575
return RPCRateLimitsResponse(
rateLimits: RPCRateLimitSnapshot(
primary: RPCRateLimitWindow.from(usage.rateLimit?.primaryWindow),
secondary: RPCRateLimitWindow.from(usage.rateLimit?.secondaryWindow),
credits: RPCCreditsSnapshot.from(usage.credits)))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate recovered payload before returning rate limits

recoverRateLimits returns a synthetic success whenever the error string contains any JSON body, but CodexUsageResponse has optional top-level fields so unrelated payloads like {"error":"unauthorized"} will decode and produce a snapshot with all fields nil. In that case fetchRateLimits no longer surfaces the original requestFailed error and downstream code reports UsageError.noRateLimitsFound instead, which masks auth/network failures and changes fallback/CLI exit behavior. Require at least one recovered field (primary, secondary, or credits) before returning a recovered response.

Useful? React with 👍 / 👎.

@ratulsarna
Copy link
Copy Markdown
Collaborator

Thanks for the PR @beginnerslvl ! This fix is already covered and merged via #710 .

@ratulsarna ratulsarna closed this Apr 15, 2026
@beginnerslvl
Copy link
Copy Markdown
Author

my bad for missing that. sorry for the extra noise here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unhandled new OpenAI prolite plan causes Codex usage fetch failure

3 participants